<?php
	namespace Common\Logic;
	use Common\Model\QuestionsModel;
	class QuestionsLogic extends QuestionsModel{
		/*
		* Function:		getQuestionsList
		* Description:	问题列表列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getQuestionsList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getQuestionsFilter($filter);
			return $this->where($conditon)->order('id desc')->limit(($page-1)*$pageSize,$pageSize)->order('sort desc,id desc')->select();
		}
		
		/*
		* Function:get:	getQuestionsFilter
		* Description:	问题列表列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getQuestionsFilter($filter = ''){
			$conditon = array();
			if(empty($filter['flag'])){
			    $conditon['status'] = 1;
			}
			if(!empty($filter['name'])){
				$conditon['name'] = array('like','%'.$filter['name'].'%');
			}
			return $conditon;
		}
		
		/*
		* Function:get:	getQuestionsCount
		* Description:	问题列表列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getQuestionsCount($filter = ''){
			$conditon = $this->getQuestionsFilter($filter);
			return $this->where($conditon)->count();
		}
		
		/*
		* Function:		addQuestions
		* Description:	增加问题列表
		* @param:		$data array 增加的数组
		*/
		public function addQuestions($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getQuestionsInfo
		* Description:	获取问题列表信息 by row
		* @param:		$id int ID
		*/
		public function getQuestionsInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		updateQuestions
		* Description:	更新问题列表
		* @param:		$data array 更新的数组
		*/
		public function updateQuestions($data){
			return $this->save($data);
		}
		
		/*
		* Function:		deleteQuestions
		* Description:	删除问题列表
		* @param:		$id int ID
		*/
		public function deleteQuestions($id){
			return $this->where(array('id'=>$id))->delete();
		}
		
		/*
		* Function:		getQuestionsAllList
		* Description:	问题所有列表
		*/
		public function getQuestionsAllList(){
			return $this->where(array('status'=>1))->select();
		}
	}
?>